import 'package:dk_flutter_base/dk_ui.dart';

class DkRectShadow extends Container {
  final ShadowOption shadowOption;

  DkRectShadow(this.shadowOption)
      : super(
          width: shadowOption.width,
          height: shadowOption.height,
          padding: shadowOption.padding,
          alignment: shadowOption.alignment,
          margin: shadowOption.margin,
          foregroundDecoration: shadowOption.foregroundDecoration,
          constraints: shadowOption.constraints,
          transform: shadowOption.transform,
          decoration: BoxDecoration(
            color: shadowOption.bgColor,
            border: shadowOption.border,
            borderRadius: shadowOption.borderRadius,
            // 也可控件一边圆角大小
            // 边色与边宽度
// 生成俩层阴影，一层绿，一层黄， 阴影位置由offset决定,阴影模糊层度由blurRadius大小决定（大就更透明更扩散），阴影模糊大小由spreadRadius决定
            boxShadow: shadowOption.boxShadows,
            image: shadowOption.image,
            gradient: shadowOption.gradient,
            backgroundBlendMode: shadowOption.backgroundBlendMode,
          ),
          child: shadowOption.child,
        );
}

class ShadowOption {
  double width;
  double height;

  Widget child;

  Color bgColor;

  Border border;

  BorderRadius borderRadius;

  List<BoxShadow> boxShadows;

  EdgeInsets padding;

  ///绘制在背景之上
  Gradient gradient;

  ///作用于背景和渐变 设置了该属性，颜色和渐变至少一个不为null
  BlendMode backgroundBlendMode;

  ///绘制在背景和渐变之上，所以不用设置背景和渐变
  DecorationImage image;

  ///补充以下几种属性
  AlignmentGeometry alignment;
  EdgeInsetsGeometry margin;
  Decoration foregroundDecoration;
  BoxConstraints constraints;
  Matrix4 transform;

  ShadowOption({
    this.child,
    this.width,
    this.height,
    this.bgColor,
    this.border,
    this.borderRadius,
    this.boxShadows,
    this.padding,
    this.gradient,
    this.backgroundBlendMode,
    this.image,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    if (null != image) {
      bgColor = null;
      gradient = null;
      backgroundBlendMode = null;
    } else if (null != gradient) {
      bgColor = null;
    } else if (null == bgColor) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.normalWithImage(
    this.child,
    Color shadowColor,
    this.image, {
    this.width,
    this.height,
    Color borderColor,
    double borderRadiusValue,
    double paddingValue,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    border = null == borderColor
        ? null
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
  }

  ShadowOption.normalWithGradient(
    this.child,
    Color shadowColor,
    this.gradient, {
    this.width,
    this.height,
    Color borderColor,
    double borderRadiusValue,
    double paddingValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    border = null == borderColor
        ? null
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
    if (null != backgroundBlendMode && null == gradient) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.normal(
    this.child,
    Color shadowColor, {
    this.width,
    this.height,
    this.bgColor,
    Color borderColor,
    double borderRadiusValue,
    double paddingValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    border = null == borderColor
        ? null
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
    if (null != backgroundBlendMode && null == bgColor) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.border(
    this.child,
    Color shadowColor,
    this.border, {
    this.width,
    this.height,
    this.bgColor,
    double borderRadiusValue,
    double paddingValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
    if (null != backgroundBlendMode && null == bgColor) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.borderRadius(
    this.child,
    Color shadowColor,
    this.borderRadius, {
    this.width,
    this.height,
    this.bgColor,
    Color borderColor,
    double paddingValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    border = null == borderColor
        ? Border()
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
    if (null != backgroundBlendMode && null == bgColor) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.padding(
    this.child,
    Color shadowColor,
    this.padding, {
    this.width,
    this.height,
    this.bgColor,
    Color borderColor,
    double borderRadiusValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    boxShadows = null == shadowColor
        ? null
        : [BoxShadow(color: shadowColor, blurRadius: 5.0)];
    border = null == borderColor
        ? null
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    if (null != backgroundBlendMode && null == bgColor) {
      backgroundBlendMode = null;
    }
  }

  ShadowOption.shadow(
    this.child,
    this.boxShadows, {
    this.width,
    this.height,
    this.bgColor,
    Color borderColor,
    double borderRadiusValue,
    double paddingValue,
    this.backgroundBlendMode,
    this.alignment,
    this.margin,
    this.foregroundDecoration,
    this.constraints,
    this.transform,
  }) {
    border = null == borderColor
        ? null
        : Border.all(color: borderColor, width: 0.5, style: BorderStyle.solid);
    borderRadius = null == borderRadiusValue
        ? null
        : BorderRadius.circular(borderRadiusValue);
    padding = null == paddingValue ? null : EdgeInsets.all(paddingValue);
    if (null != backgroundBlendMode && null == bgColor) {
      backgroundBlendMode = null;
    }
  }
}
